package com.ostrich.module_community.recommend

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.StaggeredGridLayoutManager
import com.ostrich.library_base.BaseMvvmFragment
import com.ostrich.library_common.utils.DensityUtils
import com.ostrich.library_common.utils.LoggerUtils
import com.ostrich.library_common.views.CustomItemDecoration
import com.ostrich.module_community.R
import com.ostrich.module_community.attention.AttentionFragment
import com.ostrich.module_community.databinding.CommunityFragmentRecommendBinding
import com.ostrich.module_community.recommend.adapter.ReCommendAdapter
import com.ostrich.module_community.recommend.entity.ReCommendEntity


class RecommendFragment : BaseMvvmFragment<CommunityFragmentRecommendBinding,RecommendViewModel>() {
   private lateinit var reCommendAdapter: ReCommendAdapter
   private var data:MutableList<ReCommendEntity> = mutableListOf()

    override fun initView() {
        binding?.let {
            reCommendAdapter = ReCommendAdapter(R.layout.community_item_community_view,data)
            it.rv.adapter = reCommendAdapter
            it.rv.layoutManager = StaggeredGridLayoutManager(2,StaggeredGridLayoutManager.VERTICAL)
            it.rv.addItemDecoration(CustomItemDecoration(2,DensityUtils.dp2px(context,10f)))
        }
    }

    override fun initData() {
        viewModel.recommend().observe(this){
            LoggerUtils.d(TAG,it.toString())


            it.itemList.removeAt(0)
            it.itemList.removeAt(0)
            reCommendAdapter.addData(it.itemList)





        }

    }

    override fun initListener() {

    }

    override fun bindLayout(): Int {
        return R.layout.community_fragment_recommend
    }

    override fun getJVMClass(): Class<RecommendViewModel> {
       return RecommendViewModel::class.java
    }
    companion object{
        const val TAG = "RecommendFragment"
    }


}